/*
Brick And Blast, a crossplatform breakout game.
 Copyright (C) 2008-2010 Julien CLEMENT (andematunum@gmail.com)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef _BatPart_h_
#define _BatPart_h_

/**
* file   BatPart.h
* date   Dim 3 jan 2010 14:15:56 CET
* brief  TODO
*/

#include "SDL.h"
#include "GameObject.h"
#include "Level.h"
class Bat;

class BatPart: public GameObject {
public:
  BatPart (Bat* bat, GameObjectType type)
    : GameObject(), bat_(bat) {
    //SDL_Rect texrect = {0, 0, 16, 16};
    set_type(type);
    switch(type) {
      case GAME_OBJECT_BAT_BORDER_LEFT: {
        //texrect.x = 0;
        //set_shape(GAME_OBJECT_CIRCLE);
        set_shape(GAME_OBJECT_RECTANGLE);
        set_texture(Level::get_bat_left(), true);
      }
      break;
      case GAME_OBJECT_BAT_BORDER_RIGHT: {
        //texrect.x = 32;
        //set_shape(GAME_OBJECT_CIRCLE);
        set_shape(GAME_OBJECT_RECTANGLE);
        set_texture(Level::get_bat_right(), true);
      }
      break;
      case GAME_OBJECT_BAT_CHUNK: {
        //texrect.x = 16;
        set_shape(GAME_OBJECT_RECTANGLE);
        set_texture(Level::get_bat_chunk(), true);
      }
      break;
      default: {
        cerr << "*** ERROR: Wrong bat part type: " << type << endl;
      }
      break;
    }
    /*SDL_Surface* sbat = Level::get_bat();
    SDL_Surface* surf = SDL_CreateRGBSurface (
      sbat->flags, 16, 16, sbat->format->BitsPerPixel,
      sbat->format->Rmask, sbat->format->Gmask, sbat->format->Bmask, sbat->format->Amask
    );
    SDL_Surface* surf = SDL_CreateRGBSurface (
      SDL_ANYFORMAT, 16, 16, 0, 0, 0, 0, 0
    );
    if (surf == NULL) {
      cerr << "*** ERROR: Cannot create a 16x16 surface for BatPart." << endl;
    }
    else {
      SDL_Rect dst =  {0, 0, 16, 16};
      SDL_UpperBlit(sbat, &texrect, surf, &dst);
      SDL_TextureID texid = SDL_CreateTextureFromSurface(0, sbat);
      SDL_SetTextureScaleMode(texid, SDL_TEXTURESCALEMODE_NONE);
      //Level::load_texture(texid,"data/gfx/bat.png");
      if (texid == 0) {
        cerr << "*** ERROR: Cannot create texture for BatPart." << endl;
      }
      else {
        set_texture(texid, true);
      }
      SDL_FreeSurface(surf);
    }*/
  }
  Bat* get_bat () {
    return bat_;
  }
private:
  Bat* bat_;
};

#endif

